package com.orientsec.autotest.project.system.systemSqlquery.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.systemSqlquery.domain.SystemSqlquery;
import com.orientsec.autotest.project.system.systemSqlquery.service.ISystemSqlqueryService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * sql查询语句信息操作处理
 * 
 * @author autotest
 * @date 2019-12-18
 */
@Controller
@RequestMapping("/system/systemSqlquery")
public class SystemSqlqueryController extends BaseController
{
    private String prefix = "system/systemSqlquery";
	
	@Autowired
	private ISystemSqlqueryService systemSqlqueryService;
	
	@RequiresPermissions("system:systemSqlquery:view")
	@GetMapping()
	public String systemSqlquery()
	{
	    return prefix + "/systemSqlquery";
	}
	
	/**
	 * 查询sql查询语句列表
	 */
	@RequiresPermissions("system:systemSqlquery:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SystemSqlquery systemSqlquery)
	{
		startPage();
        List<SystemSqlquery> list = systemSqlqueryService.selectSystemSqlqueryList(systemSqlquery);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出sql查询语句列表
	 */
	@RequiresPermissions("system:systemSqlquery:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SystemSqlquery systemSqlquery)
    {
    	List<SystemSqlquery> list = systemSqlqueryService.selectSystemSqlqueryList(systemSqlquery);
        ExcelUtil<SystemSqlquery> util = new ExcelUtil<SystemSqlquery>(SystemSqlquery.class);
        return util.exportExcel(list, "systemSqlquery");
    }
	
	/**
	 * 新增sql查询语句
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存sql查询语句
	 */
	@RequiresPermissions("system:systemSqlquery:add")
	@Log(title = "sql查询语句", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SystemSqlquery systemSqlquery)
	{		
		return toAjax(systemSqlqueryService.insertSystemSqlquery(systemSqlquery));
	}

	/**
	 * 修改sql查询语句
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		SystemSqlquery systemSqlquery = systemSqlqueryService.selectSystemSqlqueryById(id);
		mmap.put("systemSqlquery", systemSqlquery);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存sql查询语句
	 */
	@RequiresPermissions("system:systemSqlquery:edit")
	@Log(title = "sql查询语句", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SystemSqlquery systemSqlquery)
	{		
		return toAjax(systemSqlqueryService.updateSystemSqlquery(systemSqlquery));
	}
	
	/**
	 * 删除sql查询语句
	 */
	@RequiresPermissions("system:systemSqlquery:remove")
	@Log(title = "sql查询语句", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(systemSqlqueryService.deleteSystemSqlqueryByIds(ids));
	}
	
}
